package com.cr.front.user.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.cr.common.response.JsonResult;
import com.cr.front.user.pojo.dto.param.UserLoginParam;
import com.cr.front.user.pojo.vo.LoginResultVO;
import com.cr.front.user.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@Api(tags = "登录模块")
@RequestMapping("/users")
public class LoginController {



    @Autowired
    private LoginService loginService;

    @ApiOperation(value = "用户登录")
    @PostMapping("login")
    public JsonResult login(@Validated @RequestBody UserLoginParam userLoginParam) {
        LoginResultVO loginResultVO = loginService.login(userLoginParam);
        return JsonResult.success(loginResultVO);
    }

    @ApiOperation(value = "退出登录")
    @PostMapping("logout")
    public JsonResult logout() {
        StpUtil.logout();
        return JsonResult.success();
    }





    /**
     * 用户登录
     * POST http://localhost:8080/v1/user/login?username=admin&password=admin
     * @param userLoginParam
     * @return
     */
//    @PostMapping("/login")
//    public JsonResult login(@RequestBody UserLoginParam userLoginParam) {
//        log.info("用户名：{}", userLoginParam.getUsername());
//        UserVO userVO = userService.login(userLoginParam);
//        return JsonResult.success(userVO);
//    }

    /**
     * 注册
     * @param username
     * @return
     */
//    @PostMapping("/reg")
//    public JsonResult reg(@RequestParam String username) {
//        log.info("用户名：{}", username);
//        //获取注册时的用户名
//        userService.reg(username);
//        return JsonResult.success();
//    }

}